<?php

use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\Schema;

return new class extends Migration {
    /**
     * Run the migrations.
     *
     * @return void
     */
    public function up()
    {
        Schema::create('users', function (Blueprint $table) {
            $table->id();
            $table->string('user_name', 50)->default('')->index()->comment('用户名');
            $table->string('wx_openid', 50)->default('')->comment('微信openid');
            $table->string('wx_unionid', 50)->default('')->comment('微信unionid');
            $table->string('avatar')->default('')->comment('头像');
            $table->string('nick_name')->default('')->comment('昵称');
            $table->decimal('balance', 20, 2)->default(0)->comment('可用余额');
            $table->unsignedBigInteger('integral')->default(0)->comment('可用积分');
            $table->decimal('total_withdrawal', 20)->default(0)->comment('累计提现金额');
            $table->boolean('is_enable')->default(0)->comment('是否启用：1是 0否');
            $table->boolean('is_delete')->default(0)->comment('是否删除：1是 0否');
            $table->dateTime('last_login_at')->default(\App\Consts\TimeConst::DEFAULT_DATE_TIME)->comment('登录时间');
            $table->string('last_login_ip', 50)->default('0.0.0.0')->comment('登录IP');
            $table->dateTime('created_at')->default(\DB::raw('CURRENT_TIMESTAMP'));
            $table->timestamp('updated_at')->default(\DB::raw('CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP'));
        });
        DB::statement("ALTER TABLE `users` COMMENT '用户'");
    }

    /**
     * Reverse the migrations.
     *
     * @return void
     */
    public function down()
    {
        if (!is_production()) Schema::dropIfExists('users');
    }
};
